package net.javashop.admin.web.controller;

import net.javashop.biz.user.UserBiz;
import net.javashop.entity.User;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/* 
 * 不需要实现任何接口，也不需要继承任何的类 
 */  
@Controller
public class HelloWordController/* extends AbstractController*/{
	 @Autowired  
	 private UserBiz userBiz;
	
	/** 
     * 方法都可以接受的参数(参数数量和顺序没有限制)： 
     * HttpServletRequest,
     * HttpServletResponse,
     * HttpSession(session必须是可用的),
     * PrintWriter,
     * Map, 
     * Model,
     * @PathVariable (任意多个), 
     * @RequestParam (任意多个), 
     * @CookieValue (任意多个),
     * @RequestHeader,Object(pojo对象),
     * BindingResult
     * 等等..
     * 
     * 
     * 返回值可以是：
     * String(视图名),
     * void(用于直接response),
     * ModelAndView,
     * Map,
     * Model
     * 任意其它任意类型的对象(默认放入model中，名称即类型的首字母改成小写),视图名默认是请求路径 
     */ 
	@RequestMapping("/welcome.do")  
	//@RequestMapping("welcome.do")   //也可以, /welcome.do, welcome.do 加不加"/"都只能映射 /应用程序名/welcome.do  
    public ModelAndView hello() {  
		System.out.println("------------------------xx---------------------");
        ModelAndView mav = new ModelAndView();  
        mav.setViewName("hello/welcome");  
        //mav.setViewName("/hello/welcome");  //也可以
        mav.addObject("message", "Hello World!"); 
        
        User entity = userBiz.getUser(1);  
        System.out.println("user biz..name：" + entity.getUsername());  
        
        return mav;  
    }

    /*
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest arg0,
			HttpServletResponse arg1) throws Exception {
		System.out.println("---------------------------------------------");
        ModelAndView mav = new ModelAndView();  
        mav.setViewName("welcome");  
        mav.addObject("message", "Hello World!");  
        return mav; 
	}  
	*/
}
